package cn.edu.hqu.cst.android.myapplication;
import java.util.Timer;
  import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity7 extends AppCompatActivity {
    private Button myBtn_one;

    // 要切换的照片，放在drawable文件夹下
        int[] images = { R.drawable.a, R.drawable.b, R.drawable.c,R.drawable.d,R.drawable.e };
 // Message传递标志
        int SIGN = 17;
// 照片索引
        int num = 0;
         @Override
public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main7);
         Button myBtn_one = (Button) findViewById(R.id.button22);
             myBtn_one.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
                     // TODO Auto-generated method stub
                     Intent intent = new Intent();
                     intent.setClass(MainActivity7.this, MainActivity.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                     startActivity(intent);
                 }
             });
         final ImageView image = (ImageView) findViewById(R.id.imageView);
         @SuppressLint("HandlerLeak") final Handler handler = new Handler() {
 @Override
public void handleMessage(Message msg) {
                 // TODO Auto-generated method stub
                super.handleMessage(msg);
                 if (msg.what == SIGN) {
                     image.setImageResource(images[num++]);
                    if (num >= images.length) {
                        num = 0;
                         }
                     }
                 }
 };
         new Timer().schedule(new TimerTask() {
 @Override
 public void run() {
                 // TODO Auto-generated method stub
                 Message msg = new Message();
                 msg.what = SIGN;
                handler.sendMessage(msg);
                 }
 },20,100);
        }
 }
